<template>
  <div>
    <el-dialog
      title="新增"
      :visible.sync="dialogVisible"
      width="500px"
      @close="handleClose"
    >
      <el-form ref="formRef" :model="form" label-width="100px">
        <el-form-item label="姓名">
          <el-input v-model="form.username" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="住址">
          <el-input v-model="form.address" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.phone" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input v-model="form.gender" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="民族">
          <el-input v-model="form.nation" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model="form.age" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="$emit('change')">取消</el-button>
        <el-button type="primary" @click="handleSubmit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { updateUserApi } from "@/api/user";
export default {
  data() {
    return {
      dialogVisible: true,
      form: {},
    };
  },
  methods: {
    handleClose() {
      this.$emit("change");
    },
    async handleSubmit() {
      const res = await updateUserApi({ ...this.form });
      if (res.code === 200) {
        this.$message.success("保存成功");
        this.$emit("change", true);
      }
    },
  },
};
</script>

<style scoped lang="scss"></style>
